package com.jgj.zxkj.lookandcheckjggroupinfo.login;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.jgj.zxkj.lookandcheckjggroupinfo.constants.Constants;
import com.sa.all_cui.mix_core.utils.storage.simpledisk.DiskLruCacheHelper;

/**
 * Created by all-cui on 2017/11/1.
 * 处理登录成功返回的数据
 */

@SuppressWarnings("WeakerAccess")
public class SignHandler {
    public static void onSignIn(String response, ISignListener signListener) {
        LogUtils.i(response);
        final JSONObject res = JSON.parseObject(response);
        final String deptName = res.getString("deptName");
        final String permission = res.getString("power");
        final String account = res.getString("loginid");
        final String success = res.getString("success");

        UserProfile profile = new UserProfile(deptName, permission, account, success);
        DiskLruCacheHelper.getInstance().put(Constants.USER_PROFILE, profile);

        if (success.equals(Constants.SUCCESS_FLAG)) {
            signListener.onSignInSuccess();
        } else {
            ToastUtils.showShort(res.getString("message"));
        }

    }
}
